package spring.datasource;

import spring.exceptions.ConnectionCloseException;

import java.sql.Connection;
import java.sql.SQLException;

public class SimpleConnectionHandle implements ConnectionHandle {

    private final Connection connection;

    public SimpleConnectionHandle(Connection connection) {
        this.connection = connection;
    }

    @Override
    public Connection getConnection() {
        return this.connection;
    }

    @Override
    public void releaseConnection(Connection con) {
        try {
            con.close();
        } catch (SQLException ex) {
            throw new ConnectionCloseException("数据库连接关闭失败", ex);
        }
    }

    @Override
    public String toString() {
        return "SimpleConnectionHandle: " + this.connection;
    }

}
